<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function getFolderNames(names) {
      const set = new Set();

      return names.map(name => {
        if (!set.has(name)) return set.add(name), name;

        for (let k = 1; k; k++) {
          const newName = name + `(${k})`;
          if (!set.has(newName)) {
            return set.add(newName), newName;
          }
        }
      });
    };
    console.log(getFolderNames(names = ["pes", "fifa", "gta", "pes(2019)"]))
  </script>
</body>

</html>